package com.acme.bankapp.domain.bank;

import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.acme.bankapp.BankApplication;

/**
 * @author Andrey Alekov
 * Bank class.
 */
public class Bank {
	final static Logger logger = LoggerFactory.getLogger(BankApplication.class);
	private String bankName;
	private List<Client> clients = new ArrayList<Client>();
	private List<AbstractClientListener> listeners = new ArrayList<AbstractClientListener>();
	
	public Bank(String bankName) {
		this.setBankName(bankName);
		class PrintClientListener extends AbstractClientListener {
			@Override
			public void onClientAdded(Client client) {
				logger.info(client.toString());
			}
		}
		final class EmailNotificationListener extends AbstractClientListener {
			@Override
			public void onClientAdded(Client client) {
				logger.info("Notification email to " + client.toString()
						+ " to be sent.");
			}
		}
		this.listeners.add(new PrintClientListener());
		this.listeners.add(new EmailNotificationListener());
	}
	
	public Bank(String bankName, List<AbstractClientListener> listeners) {
		this.setBankName(bankName);
		this.listeners = listeners;
	}

	public List<Client> getClients(){
		return this.clients;
	}

	public String getBankName() {
		return bankName;
	}

	public void setBankName(String bankName) {
		this.bankName = bankName;
	}

	/*
	 * Method prints maximum amount to withdraw for each client.
	 * @param client to add
	 */
	public void addClient(Client client){
		this.clients.add(client);
		for (ClientRegistrationListener listener : this.listeners) {
			listener.onClientAdded(client);
		}
	}
	/*
	 * Method prints maximum amount to withdraw for each client.
	 */
	public void printMaximumAmountToWithdraw() {
		for (Client client : clients) {
			logger.info("Client: " + client.getName() + " ; " + "Max amount:" +
					client.getAccount().maximumAmountToWithdraw());
		}
	}
}

